package com.xyht.medicine_management_system.modules.aboutUs.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.aboutUs.entity.req.MmsAboutUsReq;
import com.xyht.medicine_management_system.modules.aboutUs.mapper.MmsAboutUsMapper;
import com.xyht.medicine_management_system.modules.aboutUs.service.MmsAboutUsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 关于我们 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-02-19
 */
@RestController
@RequestMapping("/aboutUs")
@SecretBody
public class MmsAboutUsController {

    @Resource
    private MmsAboutUsService mmsAboutUsService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("添加关于我们信息")
    @PostMapping("/add")
    public ResponseResult addAboutUs(HttpServletRequest request, @RequestBody MmsAboutUsReq addReq) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsAboutUsService.addAboutUs(userId,addReq);
    }

    @ApiOperation("修改关于我们信息")
    @PostMapping("/update")
    public ResponseResult updateAboutUs(@RequestBody MmsAboutUsReq updateReq) {
        return mmsAboutUsService.updateAboutUs(updateReq);
    }

    @ApiOperation("获取关于我们详情")
    @GetMapping("/detail")
    public ResponseResult getAboutUsDetail() {
        return mmsAboutUsService.getAboutUsDetail();
    }

    @ApiOperation("获取关于我们列表")
    @GetMapping("/list")
    public ResponseResult getAboutUsList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "search",  required = false) String search) {
        return mmsAboutUsService.getAboutUsList(pageNum,pageSize,search);
    }

}

